using System.ComponentModel.Design;
using PrismFactory.SoftwareFactory.Views.Properties;
using PrismGuidancePackage.Views.Services;

namespace PrismFactory.SoftwareFactory.Views.CreateSolution
{
    public class EnsureEntlibAssembliesPathPageViewModel : ViewModelBase
    {
        public const string EntlibAssembliesPathKey = "EntlibAssembliesPath";

        private readonly IDictionaryService dictionaryService;
        private readonly IFileSystemService fileSystemService;

        public EnsureEntlibAssembliesPathPageViewModel(IDictionaryService dictionaryService, IFileSystemService fileSystemService)
        {
            this.dictionaryService = dictionaryService;
            this.fileSystemService = fileSystemService;
            ValidatedProperties = new[]
                                      {
                                          EntlibAssembliesPathKey,
                                      };
        }

        public string EntlibAssembliesPath
        {
            get { return (string) dictionaryService.GetValue(EntlibAssembliesPathKey); }
            set
            {
                dictionaryService.SetValue(EntlibAssembliesPathKey, value);
                OnPropertyChanged(EntlibAssembliesPathKey);
            }
        }

        protected override void DoPropertyValidation(string propertyName, ref string error)
        {
            switch (propertyName)
            {
                case EntlibAssembliesPathKey:
                    if (!fileSystemService.PathExists(EntlibAssembliesPath))
                        error = Resources.InvalidPath;
                    break;
            }
        }
    }
}